﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class api_tools : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        convertText(1);
    }

    protected void convertText(int type) 
    {
        string source = TextBox1.Text;
        string[] args = source.Split(new string[] { "\r\n" }, StringSplitOptions.None);
        StringBuilder result = new StringBuilder();
        if (type != 3)
        {
            result.AppendLine("StringBuilder result = new StringBuilder();");
        }
        foreach (string arg in args) 
        {
            string arg1 = arg.Replace("\"", "\\\"");
            switch (type) 
            {
                
                case 1:
                    result.AppendFormat("result.Append(\"{0}\\r\\n\");\r\n", arg1);
                    break;
                case 2:
                    result.AppendFormat("result.AppendLine(\"{0}\");\r\n", arg1);
                    break;
                case 3:
                    result.AppendFormat("document.write(\"{0}\");\r\n", arg1);
                    break;
                default:
                    result.AppendFormat("result.Append(\"{0}\");\r\n", arg1);
                    break;
            }
        }

        this.TextBox2.Text = result.ToString();
        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        convertText(2);
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        convertText(3);
    }
}